package com.galaxy.order.api;

import cn.hutool.core.util.PageUtil;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.order.domain.OrderReview;
import com.galaxy.order.domain.bo.OrderReviewBo;
import com.galaxy.order.domain.vo.OrderReviewVo;
import com.galaxy.order.service.OrderReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序订单评价信息Controller
 */
@Validated
@RestController
@RequestMapping("/api/orderReview")
public class OrderReviewApiController {
    @Autowired
    private OrderReviewService orderReviewService;

    /**
     * 分页查询订单评价信息列表
     */
    @GetMapping("/list")
    public TableDataInfo<OrderReviewVo> list(OrderReviewBo bo, PageQuery pageQuery) {
        return orderReviewService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单评价详细信息
     */
    @GetMapping("/{id}")
    public R<OrderReview> getInfo(@PathVariable("id") Long id) {
        return R.ok(orderReviewService.queryById(id));
    }

    @GetMapping("/getInfoByOrder/{orderId}")
    public R<OrderReview> getInfoByOrder(@PathVariable("orderId") Long orderId) {
        return R.ok(orderReviewService.getInfoByOrder(orderId));
    }

    /**
     * 新增订单评价信息
     */
    @PostMapping
    public R<Boolean> add(@Validated @RequestBody OrderReviewBo bo) {
        return R.ok(orderReviewService.insertByBo(bo));
    }

    /**
     * 修改订单评价信息
     */
    @PutMapping
    public R<Boolean> edit(@Validated @RequestBody OrderReviewBo bo) {
        return R.ok(orderReviewService.updateByBo(bo));
    }

    /**
     * 删除订单评价信息
     */
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable Long[] ids) {
        return R.ok(orderReviewService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 查询订单评价信息列表（不分页）
     */
    @GetMapping("/listOrderReview")
    public R<List<OrderReviewVo>> list(OrderReviewBo bo) {
        return R.ok(orderReviewService.queryList(bo));
    }

    /**
     * 通过商品ID查询评论列表
     */
    @GetMapping("/product")
    public TableDataInfo<OrderReviewVo> listByProductId(Long productId, PageQuery pageQuery) {
        TableDataInfo<OrderReviewVo> orderReviewVoTableDataInfo = orderReviewService.queryByProductId(productId, pageQuery);
        return orderReviewVoTableDataInfo;
    }
}
